package com.douqu.game.auth.server;

import com.douqu.game.core.e.E_ProfileVersion;
import com.douqu.game.core.util.LogUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;

import javax.validation.constraints.NotNull;

/**
 * Created by bean
 * 2017-03-23 16:58.
 */
public class SpringContext
{
    /**
     * spring管理器
     */
    private static ApplicationContext applicationContext;

    public static void init(ApplicationContext ac)
    {
        applicationContext = ac;
    }

    public static <T> T getBean(Class cls)
    {
        return (T) applicationContext.getBean(cls);
    }

    public static <T> T getBean(String name)
    {
        return (T) applicationContext.getBean(name);
    }

//    public static PlatformSDK getPlatformSDK(Class cls){
//        return SpringContext.getBean(cls);
//    }

    public static void stop()
    {
        SpringApplication.exit(applicationContext);
    }

    public static String getProperty(@NotNull final String property){
        Environment environment = getBean(Environment.class);
        return environment.getProperty(property);
    }

//    public static boolean isDev()
//    {
//        return getProperty("ver").equals(E_ProfileVersion.DEV.getKey());
//    }

    public static void showConfig()
    {
        Environment env = getBean(Environment.class);
        String ver = env.getProperty("profile");
        LogUtils.info("VERSION ------------>" + ver + " -> " + E_ProfileVersion.forKey(ver));
        LogUtils.info("DBUrl--------------->" + env.getProperty("spring.datasource.url"));
    }
}
